package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.AdminRoleMenu;
import com.dingreading.cloud.admin.entity.table.AdminRoleMenuTableDef;
import com.dingreading.cloud.admin.mapper.AdminRoleMenuMapper;
import com.dingreading.cloud.admin.service.AdminRoleMenuService;
import com.mybatisflex.core.query.QueryCondition;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class AdminRoleMenuServiceImpl extends BaseServiceImpl<AdminRoleMenuMapper, AdminRoleMenu, AdminRoleMenuTableDef> implements AdminRoleMenuService {

    @Override
    protected AdminRoleMenuTableDef getTable() {
        return AdminRoleMenuTableDef.adminRoleMenu;
    }

    @Override
    public int dropByRoleId(Long roleId) {
        return getMapper().deleteByCondition(table.roleId.eq(roleId));
    }

    @Override
    public List<AdminRoleMenu> getByRoleId(Long roleId) {
        return getMapper().selectListByCondition(table.roleId.eq(roleId));
    }

    @Override
    public int dropByRoleIdNotMenuIds(Long roleId, List<Long> menuIds) {
        QueryCondition condition = table.roleId.eq(roleId)
                .and(table.menuId.notIn(menuIds));
        return getMapper().deleteByCondition(condition);
    }

    @Override
    public int dropByMenuId(Long menuId) {
        QueryCondition condition = table.menuId.eq(menuId);
        return getMapper().deleteByCondition(condition);
    }

}
